← Back
Editing: gr_single_primary_and_leader_election.test
################################################################### # WL#9426: Single Primary Mode in Group Replication # # Validate that leader election takes place while creating # the group and while shutting it down. When shutting down # we do it by always stopping the primary first. # # Test: # # - Stage #1 # - create the group, one by one. The PRIMARY is the first # server in the group # - for each server check what its role is and whether # it is RO or RW as expected # - Check that there are 1 PRIMARY per iteration and that # there are N secondaries as expected. # # - Stage #2 # - Find the primary server in the group # - stop it # - Find the next server still in the group # - Count primaries and secondaries after the group installed # a new view. # - Find the new primary on the new view # - assert that it is RW # - assert that the PRIMARY has indeed changed. # # - Stage #3 # - clean up # ################################################################## --source ../inc/have_group_replication_plugin.inc --let $rpl_skip_group_replication_start= 1 --let $rpl_server_count= 4 --let $rpl_group_replication_single_primary_mode=1 --let $ceiling= `SELECT $rpl_server_count + 1` --source ../inc/group_replication.inc --echo # --echo # Stage 1. Watch PRIMARY and SECONDARIES being set as we grow the group. --echo # --let $i=1 while ($i < $ceiling) { --let $rpl_connection_name= server$i --source include/rpl_connection.inc # This assert can be turned into something that enforces # super read only to RW. The point is to verify that the # server later on is put into super_read_only mode --let $assert_cond= "[SELECT @@GLOBAL.super_read_only]" = 0 --let $assert_text= Assert that before joining the group the server is RW. --source include/assert.inc # # 1. Start the group and check that the server that started it # has become the PRIMARY # if (`SELECT $i=1`) { --let $read_only= 0 --let $assert_text= Assert that PRIMARY is now RW. --let $primary_server_id=`SELECT @@server_id` --let $primary_server_uuid=`SELECT @@server_uuid` --source ../inc/start_and_bootstrap_group_replication.inc } # # 2,3,4. Add another servers to the group and make sure that # they are added as SECONDARY # if ($i > 1) { --let $read_only= 1 --let $assert_text= Assert that SECONDARY is now RO. --source include/start_group_replication.inc } # wait for the member to point PRIMARY node # 1 - PRIMARY / 2,3,4 - SECONDARY --let $group_replication_expected_uuid=$primary_server_uuid --source ../inc/gr_wait_primary_member_uuid.inc # check that the server has turned ON/OFF the expected super_read_only flag # we wait since the setting of the role and unsetting of super_read_only # is not atomic --let $wait_condition= SELECT @@super_read_only = $read_only --source include/wait_condition_or_abort.inc # Lets count secondaries and primaries in the group --let $group_replication_primaries_count_in_var= 1 --let $group_replication_secondaries_count_in_var= `SELECT $i-1` --source ../inc/gr_wait_for_role_count.inc # Lets assert that the primary continues RW --source ../inc/gr_find_a_primary.inc if ($group_replication_found_primary_out_var) { --let $rpl_connection_name= $group_replication_primary_connection_out_var --source include/rpl_connection.inc } if (!$group_replication_found_primary_out_var) { --echo performance_schema.replication_group_members --echo -------------------------------------------- --query_vertical SELECT * FROM performance_schema.replication_group_members --die "Unable to find PRIMARY server!!" } --let $assert_cond= "[SELECT @@GLOBAL.super_read_only]" = 0 --let $assert_text= Assert that PRIMARY has not changed its super_read_only setting. --source include/assert.inc # Lets assert that the current primary has not changed --let $assert_cond= "[SELECT @@GLOBAL.server_id]" = $primary_server_id --let $assert_text= Assert that PRIMARY server has not changed. --source include/assert.inc --inc $i } --echo # --echo # Stage 2. Watch the primary rotate as we tear down the group. --echo # Always stopping the primary first - worst case scenario. --echo # # the PRIMARY server connection may not be deterministic --let $rpl_connection_silent=1 --let $i= 1 while($i < $ceiling) { # find a primary server and switch connection to it --source ../inc/gr_find_a_primary.inc if ($group_replication_found_primary_out_var) { --let $rpl_connection_name= $group_replication_primary_connection_out_var --source include/rpl_connection.inc --let $primary_server_id=`SELECT @@server_id` } if (!$group_replication_found_primary_out_var) { --echo performance_schema.replication_group_members --echo -------------------------------------------- --query_vertical SELECT * FROM performance_schema.replication_group_members --die "Unable to find PRIMARY server!!" } # stop current primary --source include/stop_group_replication.inc if ($i<$rpl_server_count) { # find the next server in the group that is ONLINE --let $i_next_server= 1 while ($i_next_server < $ceiling) { --let $rpl_connection_name= server$i_next_server --source include/rpl_connection.inc --let $member_id= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) let $is_online=`SELECT COUNT(*)=1 FROM performance_schema.replication_group_members WHERE member_id="$member_id" AND member_state="ONLINE"`; if ($is_online) { --let $i_next_server=$ceiling } if (!$is_online) { --inc $i_next_server } } if (!$is_online) { --die "Unable to find the next ONLINE server in the group!!" } # wait for the view to be installed --let $group_replication_number_of_members= `SELECT 5 - $i - 1` --source ../inc/gr_wait_for_number_of_members.inc # Lets count secondaries and primaries in the group --let $group_replication_primaries_count_in_var= 1 --let $group_replication_secondaries_count_in_var= `SELECT 5 - $i - 2` --source ../inc/gr_wait_for_role_count.inc # Lets assert that the primary continues RW --source ../inc/gr_find_a_primary.inc if ($group_replication_found_primary_out_var) { --let $rpl_connection_name= $group_replication_primary_connection_out_var --source include/rpl_connection.inc } if (!$group_replication_found_primary_out_var) { --die "Unable to find PRIMARY server!!" } --let $assert_cond= "[SELECT @@GLOBAL.super_read_only]" = 0 --let $assert_text= Assert that PRIMARY changed its super_read_only setting from RO to RW. --source include/assert.inc # Lets assert that the current primary HAS changed --let $assert_cond= "[SELECT @@GLOBAL.server_id]" <> $primary_server_id --let $assert_text= Assert that PRIMARY server HAS changed. --source include/assert.inc } --inc $i } --echo # --echo # Stage 3. Clean up. --echo # # restore this --let $rpl_connection_silent=0 --source ../inc/group_replication_end.inc
Save File
Cancel